package com.gqh.weather.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gqh.weather.domain.entity.YjStudentAnswerScore;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 学生答案评分Mapper接口
 */
@Mapper
public interface YjStudentAnswerScoreMapper extends BaseMapper<YjStudentAnswerScore> {
    
    /**
     * 根据学生ID列表、题目ID和角色获取评分记录
     *
     * @param studentIds 学生ID列表
     * @param qid 题目ID
     * @param role 角色
     * @return 评分记录列表
     */
    @Select("<script>" +
           "SELECT * FROM zh_student_answer_score " +
           "WHERE student_id IN " +
           "<foreach item='item' collection='studentIds' open='(' separator=',' close=')'>" +
           "#{item}" +
           "</foreach>" +
           " AND qid = #{qid} AND st_role = #{role} AND is_deleted = 0" +
           "<if test='teacherAccount != null and teacherAccount != \"\"'>" +
           " AND teacher_account = #{teacherAccount}" +
           "</if>" +
           "</script>")
    List<YjStudentAnswerScore> selectByStudentIdsAndQidAndRole(
        @Param("studentIds") List<Integer> studentIds,
        @Param("qid") Integer qid,
        @Param("role") Integer role,
        @Param("teacherAccount") String teacherAccount);
    
    /**
     * 根据学生ID、题目ID和角色获取评分记录
     *
     * @param studentId 学生ID
     * @param qid 题目ID
     * @param role 角色
     * @param teacherAccount 老师账号
     * @return 评分记录列表
     */
    @Select("<script>SELECT * FROM zh_student_answer_score " +
           "WHERE student_id = #{studentId} AND qid = #{qid} AND st_role = #{role} AND is_deleted = 0" +
           "<if test='teacherAccount != null and teacherAccount != \"\"'>" +
           " AND teacher_account = #{teacherAccount}" +
           "</if></script>")
    List<YjStudentAnswerScore> selectByStudentIdAndQidAndRole(
        @Param("studentId") Integer studentId,
        @Param("qid") Integer qid,
        @Param("role") Integer role,
        @Param("teacherAccount") String teacherAccount);
    
    /**
     * 根据任务ID、试卷类型和题目ID获取评分记录
     *
     * @param taskId 任务ID
     * @param paperType 试卷类型
     * @param qid 题目ID
     * @return 评分记录列表
     */
    @Select("SELECT * FROM zh_student_answer_score " +
           "WHERE task_id = #{taskId} AND paper_type = #{paperType} AND qid = #{qid} AND is_deleted = 0")
    List<YjStudentAnswerScore> selectByTaskIdAndPaperTypeAndQid(
        @Param("taskId") Integer taskId,
        @Param("paperType") Integer paperType,
        @Param("qid") Integer qid);
}